package com.wing.res.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wing.common.utils.PageResult;
import com.wing.system.model.response.DingTalkAttendanceBanVO;
import com.wing.system.service.DingTalkAttendanceBanCiService;
import com.wing.system.service.DingTalkAttendanceService;
import com.wing.web.annotation.RequestObjectFieldIgnore;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 *
 * @author
 */
@Validated
@Api(value = "Admin-钉钉考勤管理第三方", tags = "#/res/dingTalkAttendanceBan/dingTalkAttendanceBanList")
@RestController("DingTalkAttendanceBanController")
@RequestMapping("res/admin/dingTalkAttendanceBan")
@RequiredArgsConstructor
public class DingTalkAttendanceBanController {

    @Autowired
    DingTalkAttendanceService dingTalkAttendanceService;

    @Autowired
    DingTalkAttendanceBanCiService dingTalkAttendanceBanCiService;


    @ApiOperation(value = "手动同步钉钉考勤班次相关数据", notes = "添加")
    @RequestObjectFieldIgnore({"id", "createTime", "remark"})
    @GetMapping("/syncDingAttendanceBanCiSystem")
    public void syncDingAttendanceBanCiSystem() throws Exception {
        dingTalkAttendanceService.syncDingAttendanceBanCiSystem();
    }




    @ApiOperation(value = "查询班次列表", notes = "搜索-任务")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "第几页", defaultValue = "1", example = "1", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "limit", value = "每页多少条", defaultValue = "10", example = "10", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "sort", value="排序字段名", defaultValue = "create_time", example = "create_time", dataType = "String", paramType = "query")
            ,@ApiImplicitParam(name = "order", value="排序规则(asc:正序, desc:倒序)", defaultValue = "asc", example = "asc", dataType = "String", paramType = "query")
    })
    @GetMapping("/list")
    public PageResult<DingTalkAttendanceBanVO> selDingTalkAttendanceBanInfo(
            @RequestParam(defaultValue = "1") Integer page
            ,@RequestParam(defaultValue = "10") Integer limit
            ,@RequestParam(defaultValue = "create_time") String sort
            ,@RequestParam(defaultValue = "asc") String order
            ,String banName

    ) {
        Page<DingTalkAttendanceBanVO> pg = new Page<>(page, limit);
        HashMap map = new HashMap();
        map.put("banName", banName);
        Page<DingTalkAttendanceBanVO> list = dingTalkAttendanceBanCiService.selDingTalkAttendanceBanInfo(pg, map);
        return new PageResult<>(list.getRecords(), list.getTotal());
    }



}
